home *** CD-ROM | disk | FTP | other *** search
- /* files.c */
-
- #include <windows.h>
- #include "fce.h"
- #include "files.h"
- #include "info.h"
- #include "message.h"
-
- extern HWND hMainWnd; /* main window handle */
- extern HWND hInfoWnd; /* popup handle */
- extern HCURSOR ArrowCursor; /* arrow cursor */
- extern HCURSOR WaitCursor;
- extern int ConnectStatus;
-
- #define POST_MSG(m) PostMessage(hDlgWnd,WM_USER,(m),0)
-
- #define USE_FCE_DRIVER
-
- #define MAX_BUF 5000
- #define MAX_STR 64
-
- /* private */
-
- static HWND hDlgWnd;
- static int NextState = STATE_IDLE;
- static int BinaryMode = FALSE;
- static char DataBuffer[MAX_BUF];
- static char ServerDir[MAX_STR];
- static char LocalDir[MAX_STR];
- static char FileName[MAX_STR];
- static char Temp[MAX_STR];
-
- void Message(LPSTR);
- int AskUser(LPSTR);
- void ShowError(int Code);
- int IsConnected(void);
-
- void SetStatusText(HWND hDlg, LPSTR Text)
- {
- SetDlgItemText(hDlg, ID_STAT_BOX, Text);
- }
-
- void AddStatusText(HWND hDlg, LPSTR Text)
- {int Len;
- Len = GetDlgItemText(hDlg, ID_STAT_BOX, (LPSTR)DataBuffer, MAX_BUF-MAX_STR);
- if(Len>0)
- {DataBuffer[Len] = '\r';
- DataBuffer[Len+1] = '\n';
- lstrcpy((LPSTR)&DataBuffer[Len+2],Text);
- SetDlgItemText(hDlg, ID_STAT_BOX, (LPSTR)DataBuffer);
- }
- }
-
- void EnableStopButton(HWND hDlg, int EnableFlag)
- {int i;
- EnableWindow(GetDlgItem(hDlg,ID_STOP_BTN), EnableFlag);
- for(i=ID_EXIT_BTN;i<=ID_DEL_BTN;i++)
- EnableWindow(GetDlgItem(hDlg,i), !EnableFlag);
- }
-
- #ifdef WIN32
- BOOL CALLBACK
- #else
- BOOL FAR PASCAL
- #endif
- FilesDlgProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
- {int i, Code;
- static long ByteCount;
- static long LastCount;
- switch (iMsg)
- {case WM_INITDIALOG:
- hDlgWnd = hDlg;
- if(IsConnected())
- {/* show local directory */
- Code = fceGetLocalDir(0, (LPSTR)LocalDir, MAX_STR);
- if(Code<0) ShowError(Code);
- else
- {LocalDir[Code] = '\0';
- SetDlgItemText(hDlg, ID_LDIR_BOX, (LPSTR)LocalDir);
- wsprintf((LPSTR)Temp,"Local directory is %s", (LPSTR)LocalDir);
- SetStatusText(hDlg,(LPSTR)Temp);
- }
- /* get server directory */
- fceGetServerDir(0,(LPSTR)ServerDir, MAX_STR);
- SetDlgItemText(hDlg, ID_SDIR_BOX, (LPSTR)ServerDir);
- wsprintf((LPSTR)Temp,"Server directory is %s", (LPSTR)ServerDir);
- AddStatusText(hDlg,(LPSTR)Temp);
- /* set BINARY mode */
- Code = fceSetMode(0,'B');
- if(Code<0) ShowError(Code);
- else
- {BinaryMode = TRUE;
- CheckRadioButton(hDlg, ID_ASC_RB, ID_BIN_RB, ID_BIN_RB);
- SetStatusText(hDlg,"BINARY mode set");
- }
- SetTimer(hDlgWnd,0,50,NULL);
- }
- else EndDialog(hDlg, 0);
- /* disable STOP button */
- EnableStopButton(hDlg, 0);
- return TRUE;
-
- case WM_TIMER:
- switch(NextState)
- {case STATE_IDLE:
- return TRUE;
- case STATE_UPLOAD:
- NextState = STATE_IDLE;
- for(i=1;i<=5;i++)
- {Code = fceDriver(0);
- if(Code<0)
- {ShowError(Code);
- NextState = STATE_CLEANUP;
- return TRUE;
- }
- if(Code==0)
- {ByteCount = fceGetInteger(0, FCE_GET_FILE_BYTES_SENT);
- InfoFileMsg(ByteCount);
- wsprintf((LPSTR)Temp,"%s uploaded (%ld bytes)",
- (LPSTR)FileName, ByteCount);
- AddStatusText(hDlg,(LPSTR)Temp);
- NextState = STATE_CLEANUP;
- return TRUE;
- }
- }
- /* display progress */
- ByteCount = fceGetInteger(0, FCE_GET_FILE_BYTES_SENT);
- if(ByteCount!=LastCount)
- {InfoFileMsg(ByteCount);
- ShowWindow(hInfoWnd,SW_SHOW);
- SendMessage(hInfoWnd,WM_USER,0,0L);
- LastCount = ByteCount;
- }
- NextState = STATE_UPLOAD;
- break;
-
- case STATE_DNLOAD:
- NextState = STATE_IDLE;
- for(i=1;i<=7;i++)
- {Code = fceDriver(0);
- if(Code<0)
- {ShowError(Code);
- NextState = STATE_CLEANUP;
- return TRUE;
- }
- if(Code==0)
- {NextState = STATE_CLEANUP;
- ByteCount = fceGetInteger(0, FCE_GET_FILE_BYTES_RCVD);
- InfoFileMsg(ByteCount);
- wsprintf((LPSTR)Temp,"%s downloaded (%ld bytes)",
- (LPSTR)FileName, ByteCount);
- AddStatusText(hDlg,(LPSTR)Temp);
- NextState = STATE_CLEANUP;
- return TRUE;
- }
- }
- /* display progress */
- ByteCount = fceGetInteger(0, FCE_GET_FILE_BYTES_RCVD);
- if(ByteCount!=LastCount)
- {InfoFileMsg(ByteCount);
- ShowWindow(hInfoWnd,SW_SHOW);
- SendMessage(hInfoWnd,WM_USER,0,0L);
- LastCount = ByteCount;
- }
- NextState = STATE_DNLOAD;
- break;
-
- case STATE_CLEANUP:
- NextState = STATE_IDLE;
- /* re-enable automatic call to seeDriver */
- fceSetInteger(0,FCE_SET_AUTO_CALL_DRIVER,1);
- /* drop info window */
- ShowWindow(hInfoWnd,SW_HIDE);
- SetCursor(ArrowCursor);
- /* disable STOP button */
- EnableStopButton(hDlg, 0);
- break;
- default:
- NextState = STATE_IDLE;
- } /* end-switch */
- return TRUE;
-
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {case ID_EXIT_BTN:
- if(AskUser("Log off server?")!=IDOK) return TRUE;
- if(!IsConnected()) return TRUE;
- ConnectStatus = FALSE;
- fceClose(0);
- KillTimer(hDlgWnd,0);
- EndDialog(hDlg, 0);
- break;
-
- case ID_STOP_BTN:
- NextState = STATE_IDLE;
- fceAbort(0);
- NextState = STATE_CLEANUP;
- Message("Aborted by User!");
- /* disable STOP button */
- EnableStopButton(hDlg, 0);
- break;
-
- case ID_FULL_BTN:
- /* get full directory list */
- if(!IsConnected())
- {EndDialog(hDlg, 0);
- break;
- }
- SetCursor(WaitCursor);
- /* change to ASCII mode */
- if(BinaryMode) fceSetMode(0,'A');
- /* get full file list */
- Code = fceGetList(0,FCE_FULL_LIST,(LPSTR)DataBuffer,MAX_BUF);
- if(Code>=0) SetStatusText(hDlg, (LPSTR)DataBuffer);
- if(BinaryMode) fceSetMode(0,'B');
- SetCursor(ArrowCursor);
- break;
-
- case ID_NAME_BTN:
- /* get directory name list */
- if(!IsConnected())
- {EndDialog(hDlg, 0);
- break;
- }
- SetCursor(WaitCursor);
- /* change to ASCII mode */
- if(BinaryMode) fceSetMode(0,'A');
- /* get filename list */
- Code = fceGetList(0,FCE_NAME_LIST,(LPSTR)DataBuffer,MAX_BUF);
- if(Code>=0) SetStatusText(hDlg, (LPSTR)DataBuffer);
- if(BinaryMode) fceSetMode(0,'B');
- SetCursor(ArrowCursor);
- break;
-
- case ID_ASC_RB:
- /* set ASCII mode */
- if(!IsConnected())
- {EndDialog(hDlg, 0);
- break;
- }
- Code = fceSetMode(0,'A');
- if(Code<0) ShowError(Code);
- else
- {BinaryMode = FALSE;
- CheckRadioButton(hDlg, ID_ASC_RB, ID_BIN_RB, ID_ASC_RB);
- AddStatusText(hDlg,"ASCII mode set");
- }
- break;
-
- case ID_BIN_RB:
- /* set BINARY mode */
- if(!IsConnected())
- {EndDialog(hDlg, 0);
- break;
- }
- Code = fceSetMode(0,'B');
- if(Code<0) ShowError(Code);
- else
- {BinaryMode = TRUE;
- CheckRadioButton(hDlg, ID_ASC_RB, ID_BIN_RB, ID_BIN_RB);
- AddStatusText(hDlg,"BINARY mode set");
- }
- break;
-
- case ID_SDIR_BTN:
- if(!IsConnected())
- {EndDialog(hDlg, 0);
- return TRUE;
- }
- /* set server directory */
- if(GetDlgItemText(hDlg, ID_SDIR_BOX, (LPSTR)ServerDir, MAX_STR)==0)
- Message("Missing directory name");
- else
- {Code = fceSetServerDir(0,(LPSTR)ServerDir);
- if(Code<0) ShowError(Code);
- fceGetServerDir(0,(LPSTR)ServerDir, MAX_STR);
- wsprintf((LPSTR)Temp,"Server directory is %s",(LPSTR)ServerDir);
- AddStatusText(hDlg,(LPSTR)Temp);
- SetDlgItemText(hDlg, ID_SDIR_BOX, (LPSTR)ServerDir);
- }
- break;
-
- case ID_LDIR_BTN:
- if(!IsConnected())
- {EndDialog(hDlg, 0);
- break;
- }
- /* set local directory */
- if(GetDlgItemText(hDlg, ID_LDIR_BOX, (LPSTR)LocalDir, MAX_STR)==0)
- Message("Missing directory name");
- else
- {Code = fceSetLocalDir(0,(LPSTR)LocalDir);
- if(Code<0) ShowError(Code);
- else
- {wsprintf((LPSTR)Temp,"Local directory is %s",(LPSTR)LocalDir);
- AddStatusText(hDlg,(LPSTR)Temp);
- }
- }
- break;
-
- case ID_GET_BTN:
- if(!IsConnected())
- {EndDialog(hDlg, 0);
- break;
- }
- /* download file */
- if(GetDlgItemText(hDlg, ID_FILE_BOX, (LPSTR)FileName, MAX_STR)==0)
- Message("Missing file name");
- else
- {/* enable STOP button */
- EnableStopButton(hDlg, 1);
- /* download the file */
- SetCursor(WaitCursor);
- /* disable AUTO */
- fceSetInteger(0,FCE_SET_AUTO_CALL_DRIVER,0);
- Code = fceGetFile(0,(LPSTR)FileName);
- if(Code<0) ShowError(Code);
- else NextState = STATE_DNLOAD;
- }
- break;
-
- case ID_PUT_BTN:
- if(!IsConnected())
- {EndDialog(hDlg, 0);
- break;
- }
- /* upload file */
- if(GetDlgItemText(hDlg, ID_FILE_BOX, (LPSTR)FileName, MAX_STR)==0)
- Message("Missing file name");
- else
- {/* enable STOP button */
- EnableStopButton(hDlg, 1);
- /* upload the file */
- SetCursor(WaitCursor);
- /* disable AUTO */
- fceSetInteger(0,FCE_SET_AUTO_CALL_DRIVER,0);
- Code = fcePutFile(0,(LPSTR)FileName);
- if(Code<0) ShowError(Code);
- else NextState = STATE_UPLOAD;
- }
- break;
-
- case ID_DEL_BTN:
- if(!IsConnected())
- {EndDialog(hDlg, 0);
- break;
- }
- /* delete file */
- if(GetDlgItemText(hDlg, ID_FILE_BOX, (LPSTR)FileName, MAX_STR)==0)
- Message("Missing file name");
- else
- {/* delete the file */
- SetCursor(WaitCursor);
- Code = fceDelFile(0,(LPSTR)FileName);
- SetCursor(ArrowCursor);
- /* check status of deletion */
- if(Code<0) ShowError(Code);
- else
- {wsprintf((LPSTR)Temp,"%s deleted",(LPSTR)FileName);
- AddStatusText(hDlg,(LPSTR)Temp);
- }
- }
- break;
-
-
- default:
- break;
- }/* end-switch (LOWORD(wParam)) */
- return TRUE;
- }
- return FALSE;
- } /* end FilesDlgProc */
-
-
-